package xyz.yeidi.controller;

import xyz.yeidi.pojo.Orderdetail;
import xyz.yeidi.service.api.OrderDetailService;
import xyz.yeidi.utils.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author JIP
 * @Date 2021-08-08 11:06
 * @Version 1.0
 * @Describe :
 */
@WebServlet("/addOrderDetail")
public class AddOrderDetailServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        OrderDetailService orderDetailService = ServiceFactory.getOrderDetailService();
        PrintWriter out = response.getWriter();
        String orderId = request.getParameter("orderId");
        String foodId = request.getParameter("foodId");
        Orderdetail orderdetail = new Orderdetail();
        orderdetail.setOrderId(Integer.valueOf(orderId));
        orderdetail.setFoodId(Integer.valueOf(foodId));
        Integer i = orderDetailService.addOrderDetail(orderdetail);
        if(i==null){
            out.print("error");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
